package cn.codeforfun.utils;

import cn.hutool.core.io.resource.ClassPathResource;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;

public class MavenUtils {

    public static MavenProject resolvePom(String pomClasspath) throws XmlPullParserException, IOException {
        InputStream stream = new ClassPathResource(pomClasspath).getStream();
        return convertPomToInstance(stream);
    }

    public static MavenProject convertPomToInstance(InputStream pomStream) throws XmlPullParserException, IOException {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        Model model = reader.read(pomStream);
        return new MavenProject(model);
    }
}
